# Use the latest Go image as the builder image
# FROM ccr.ccs.tencentyun.com/pdabase/gobase-1.23:latest AS builder
FROM ccr.ccs.tencentyun.com/my.repo/newsletter-subs:gobase AS builder

# Set the working directory
WORKDIR /gobuild

# Copy go mod and sum files
COPY go.mod go.sum ./

# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go env -w GOPROXY=https://goproxy.cn

# Download dependencies
RUN go mod download

# Copy the source code into the container
COPY . .

# Build the application
RUN go build -o /newsletter-subs

# Use the latest Go image as the base image
# FROM ccr.ccs.tencentyun.com/pdabase/gobase-1.23:latest
FROM ccr.ccs.tencentyun.com/my.repo/newsletter-subs:gobase

# Set the working directory
WORKDIR /app

# Copy build foler to execution
COPY --from=builder /newsletter-subs /app/newsletter-subs

# Expose port 8080 for the API
EXPOSE 8080

# Set the entrypoint to the compiled binary
ENTRYPOINT ["/app/newsletter-subs"]